/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Other;

import java.io.DataInputStream;
import java.io.FileInputStream;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;

/**
 *
 * @author Envy
 */
public class DecryptSymmetric {

    public byte[] DecryptSymmetric(byte[] data, String sck_path) {
        try {
            //byte[] data = _data.getBytes();   
            DataInputStream dis = new DataInputStream(new FileInputStream(sck_path));
            byte[] buff = new byte[dis.available()];
            dis.readFully(buff);
            dis.close();

            DESKeySpec ds = new DESKeySpec(buff);
            SecretKeyFactory skf = SecretKeyFactory.getInstance("DES");
            SecretKey desKey = skf.generateSecret(ds);

            Cipher decypher;
            decypher = Cipher.getInstance("DES/ECB/PKCS5Padding");
            decypher.init(Cipher.DECRYPT_MODE, desKey);
            byte[] result = decypher.doFinal(data);
            String result1 = new String(result);

            return result;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }
}
